package com.nec.recommend.module.weapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nec.recommend.auth.AuthUser;
import com.nec.recommend.consts.CacheGroupConst;
import com.nec.recommend.consts.TokenConst;
import com.nec.recommend.module.weapp.entity.WeappUser;
import com.nec.recommend.module.weapp.mapper.WeappUserMapper;
import com.nec.recommend.module.weapp.service.WeappUserService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class WeappUserServiceImpl extends ServiceImpl<WeappUserMapper, WeappUser> implements WeappUserService {
    private final RedisTemplate<String, Object> redisTemplate;

    public WeappUserServiceImpl(@Qualifier("customRedisTemplate") RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public void refreshUserInfo(AuthUser authUser) {
        redisTemplate.opsForValue().set(CacheGroupConst.WEAPP_USER_SESSION + authUser.getToken(), authUser, TokenConst.TOKEN_EXPIRE, TokenConst.EXPIRE_UNIT);
    }
}
